<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var maxDistance = function (colors) {
      let res = 0;
      for (let i = 0; i < colors.length; i++) {
        for (let j = i + 1; j < colors.length; j++) {
          if (colors[i] != colors[j]) {
            res = Math.max(res, j - i)
          }
        }
      }
      return res
    }
    console.log(maxDistance(
      colors = [{
        house: '1',
        color: 'red'
      },
      {
        house: '2',
        color: 'blue'
      }]
    ))
  </script>
</body>

</html>